package com.hfh.url;

import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URL;
import java.net.URLConnection;

/**
 * @Author hfh
 * @Date 2022 09 13 22 33
 **/
public class URLDemo {

    public static void main(String[] args) throws Exception {
        String imgPath = "https://t7.baidu.com/it/u=407688855,3169248799&fm=193&f=GIF";
        URL url = new URL(imgPath);
        // 建立连接
        URLConnection connection = url.openConnection();

        InputStream is = connection.getInputStream();
        OutputStream os = new FileOutputStream("day23\\file\\copy.jpg");

        byte[] bys = new byte[1024];
        int len;
        while ((len = is.read(bys)) != -1) {
            os.write(bys, 0, len);
        }

        os.close();
        is.close();


    }
}
